<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="el_card">
      <div id="main" style="width: 600px; height: 400px"></div>
      <div id="main1" style="width: 450px; height: 450px"></div>
    </el-card>
  </div>
</template>

<script>
//导入echarts
import _ from 'lodash'
export default {
  data() {
    return {
      option: {
        legend: {
          top: 'bottom',
        },
        series: [
          {
            name: '半径模式',
            type: 'pie',
            radius: [20, 140],
            center: ['50%', '50%'],
            roseType: 'radius',
            itemStyle: {
                borderRadius: 5
            },
            label: {
                show: false
            },
            emphasis: {
                label: {
                    show: true
                }
            },
            data: [
                {value: 40, name: '热门推荐'},
                {value: 33, name: '海外购'},
                {value: 28, name: '苏宁房产'},
                {value: 22, name: '手机相机'},
                {value: 20, name: '电脑办公'}
            ]
        },
        ],
      },
      options: {
        title: {
          text: '用户来源',
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3',
            },
          },
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true,
        },
        xAxis: [
          {
            boundaryGap: false,
          },
        ],
        yAxis: [
          {
            type: 'value',
          },
        ],
      },
    }
  },
  async mounted() {
    let echarts = require('echarts')
    var myChart = echarts.init(document.getElementById('main'))
    var myChart1 = echarts.init(document.getElementById('main1'))
    // 指定图表的配置项和数据
    const { data: res } = await this.$http.get('/reports/type/1')
    if (res.meta.status !== 200) {
      return this.$message.error('获取折线图数据失败')
    }
    //准备数据和配置项
    const result = _.merge(res.data, this.options)
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(result)
    myChart1.setOption(this.option)
  },
}
</script>

<style lang="less" scoped>
.el_card{
#main{
  float: left;
}
#main1{
  float: right;
}
}
</style>